package Model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回json数据模板
 *
 * */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MsgJson {
    //状态码 100成功 200失败
    private int code;
    //提示信息
    private String msg;
    //返回给浏览器的数据用HashMap存储
    private Map<String,Object> extend =new HashMap<String,Object>();

    //处理json成功，返回信息
    public static MsgJson success(){
        MsgJson result=new MsgJson();
        result.setCode(0);
        result.setMsg("处理成功！");
        return result;
    }
    //处理json失败
    public static MsgJson fail(){
        MsgJson result=new MsgJson();
        result.setCode(200);
        result.setMsg("处理失败！");
        return result;
    }

    //具体页面信息的内容叠加
    public MsgJson add(String key,Object value){
        this.getExtend().put(key,value);
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }

    @Override
    public String toString() {
        return "MsgJson{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", extend=" + extend +
                '}';
    }

}
